package com.starry.module.system.core.member.controller.admin;

import cn.hutool.http.HttpStatus;
import com.starry.core.common.domain.R;
import com.starry.core.common.domain.vo.PageVo;
import com.starry.core.web.core.controller.BaseController;
import com.starry.module.system.api.member.domain.qo.MemberUserPageQo;
import com.starry.module.system.api.member.domain.qo.MemberUserQo;
import com.starry.module.system.api.member.domain.vo.MemberUserDtlVo;
import com.starry.module.system.api.member.domain.vo.MemberUserVo;
import com.starry.module.system.core.member.service.MemberUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
 * 会员用户
 * @author xiaoke
 */
@Tag(name = "会员用户")
@RestController
@RequestMapping("/system/memberUser")
public class MemberUserController extends BaseController {

    private final MemberUserService memberUserService;

    public MemberUserController(MemberUserService memberUserService) {
        this.memberUserService = memberUserService;
    }

    /**
     * 分页查询
     *
     * @param pageQo 查询实体
     * @return 所有数据
     */
    @Operation(summary = "会员用户-分页查询")
    @GetMapping("memberUserPage")
    public R<PageVo<MemberUserVo>> findPage(MemberUserPageQo pageQo) {
        return success(this.memberUserService.page(pageQo));
    }

    /**
     * 详情
     *
     * @param id 主键
     * @return 单条数据
     */
    @Operation(summary = "会员用户-详情")
    @GetMapping("memberUserDetails/{id}")
    public R<MemberUserDtlVo> findById(@PathVariable("id") Long id) {
        return success(this.memberUserService.getByIdDtl(id));
    }

    /**
     * 新增数据
     *
     * @param memberUserQo 实体对象
     * @return 新增结果
     */
    @Operation(summary = "会员用户-新增")
    @PostMapping("memberUserCreate")
    public R<Long> insert(@RequestBody @Validated MemberUserQo memberUserQo) {
        return success(HttpStatus.HTTP_CREATED, this.memberUserService.save(memberUserQo));
    }

    /**
     * 修改数据
     *
     * @param memberUserQo 实体对象
     * @return 修改结果
     */
    @Operation(summary = "会员用户-修改")
    @PostMapping("memberUserUpdate")
    public R<Void> update(@RequestBody @Validated MemberUserQo memberUserQo) {
        this.memberUserService.updateById(memberUserQo);
        return success();
    }

    /**
     * 删除数据
     *
     * @param idList 主键集合
     * @return Void
     */
    @Operation(summary = "会员用户-删除")
    @PostMapping("memberUserRemove")
    public R<Void> delete(@RequestParam("idList") Set<Long> idList) {
        this.memberUserService.removeByIds(idList);
        return success();
    }

    /**
     * 启用数据
     *
     * @param idList 主键集合
     * @return Void
     */
    @Operation(summary = "会员用户-启用")
    @PostMapping("memberUserEnable")
    public R<Void> enable(@RequestParam("idList") Set<Long> idList) {
        this.memberUserService.enable(idList);
        return success();
    }

    /**
     * 禁用数据
     *
     * @param idList 主键集合
     * @return Void
     */
    @Operation(summary = "会员用户-禁用")
    @PostMapping("memberUserDisable")
    public R<Void> disable(@RequestParam("idList") Set<Long> idList) {
        this.memberUserService.disable(idList);
        return success();
    }
}

